package com.changgou.pay.util;

import com.github.wxpay.sdk.WXPayUtil;
import entity.HttpClient;

import java.util.Map;

public class PayUtil {

    /****
     * 发送http请求封装
     * @param param
     * @param partnerkey
     * @param url
     * @return
     * @throws Exception
     */
    public static Map<String, String> sendRequest(Map param, String partnerkey, String url) throws Exception {
        //将参数转化为带签名的xml文档
        String xmlParam = WXPayUtil.generateSignedXml(param, partnerkey);
        //发送请求
        HttpClient httpClient = new HttpClient(url);
        httpClient.setXmlParam(xmlParam);
        httpClient.setHttps(true);
        httpClient.post();

        //获取返回数据
        String result = httpClient.getContent();
        return WXPayUtil.xmlToMap(result);
    }
}
